<template>
  <el-card class="member-card" shadow="hover" :body-style="{ padding: '0' }">
    <!-- 卡片头部 -->
    <div class="card-header">
      <div 
        class="card-cover"
        :style="{ backgroundImage: 'url(' + info.avatar + ')' }"
      ></div>
      
      <el-avatar 
        class="card-avatar" 
        :size="100" 
        :src="info.avatar" 
        @click.stop="router.push({ path: `user/${info.id}/article` })"
      >
        <el-icon><Picture /></el-icon>
      </el-avatar>
      
      <div class="card-info">
        <h3 
          class="card-name" 
          @click.stop="router.push({ path: `user/${info.id}/article` })"
        >
          {{ info.user.name }}
        </h3>
        <el-tag 
          class="card-school" 
          type="info" 
          size="small"
          effect="plain"
        >
          {{ info.school.name + '-' + info.major.name }}
        </el-tag>
      </div>
    </div>

    <!-- 卡片内容 -->
    <div class="card-content">
      <!-- 标签页导航 -->
      <el-tabs 
        v-model="activeTab" 
        class="member-tabs"
        @tab-change="handleTabChange"
      >
        <!-- 个人简介 -->
        <el-tab-pane label="个人简介" name="about">
          <div class="tab-content">
            <div class="content-section">
              <el-icon class="section-icon"><User /></el-icon>
              <div class="section-content">
                <p class="description" v-if="info.description">
                  {{ info.description }}
                </p>
                <el-empty 
                  v-else 
                  description="暂无个人简介" 
                  :image-size="60"
                />
              </div>
            </div>
          </div>
        </el-tab-pane>

        <!-- 工作经历 -->
        <el-tab-pane label="工作经历" name="experience">
          <div class="tab-content">
            <div class="content-section">
              <el-icon class="section-icon"><Briefcase /></el-icon>
              <div class="section-content">
                <div class="work-info" v-if="info.job && info.job != 0">
                  <el-tag type="success" effect="light">
                    <el-icon><OfficeBuilding /></el-icon>
                    {{ info.job }}
                  </el-tag>
                </div>
                <el-empty 
                  v-else 
                  description="暂时没有工作信息" 
                  :image-size="60"
                />
              </div>
            </div>
          </div>
        </el-tab-pane>

        <!-- 联系方式 -->
        <el-tab-pane label="联系方式" name="contact">
          <div class="tab-content">
            <div class="contact-list">
              <!-- 工作信息 -->
              <div class="contact-item">
                <el-icon class="contact-icon"><Location /></el-icon>
                <div class="contact-content">
                  <span class="contact-label">工作</span>
                  <span class="contact-value">
                    {{ info.job && info.job != 0 ? info.job : '暂时没有工作信息' }}
                  </span>
                </div>
              </div>
              
              <!-- 个人主页 -->
              <div class="contact-item">
                <el-icon class="contact-icon"><Link /></el-icon>
                <div class="contact-content">
                  <span class="contact-label">主页</span>
                  <el-link 
                    v-if="info.homePage && info.homePage != 0"
                    :href="info.homePage" 
                    target="_blank" 
                    type="primary"
                    class="contact-link"
                  >
                    {{ info.homePage }}
                  </el-link>
                  <span v-else class="contact-value">暂无个人主页</span>
                </div>
              </div>
              
              <!-- 邮箱 -->
              <div class="contact-item">
                <el-icon class="contact-icon"><Message /></el-icon>
                <div class="contact-content">
                  <span class="contact-label">邮箱</span>
                  <el-link 
                    :href="'mailto:' + info.user.email" 
                    type="primary"
                    class="contact-link"
                  >
                    {{ info.user.email }}
                  </el-link>
                </div>
              </div>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </el-card>
</template>

<script setup>
import { ref } from 'vue'
import { 
  Picture, 
  User, 
  Briefcase, 
  Location, 
  Link, 
  Message,
  OfficeBuilding
} from '@element-plus/icons-vue'
import router from '../../router'

const props = defineProps({
  info: Object,
})

// 当前激活的标签页
const activeTab = ref('about')

// 标签页切换处理
const handleTabChange = (tabName) => {
  activeTab.value = tabName
}
</script>

<style scoped lang="scss">
.member-card {
  max-width: 380px;
  margin: 0 auto;
  border-radius: 16px;
  overflow: hidden;
  transition: all 0.3s ease;
  border: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  
  &:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  }
  
  :deep(.el-card__body) {
    padding: 0;
  }
}

// 卡片头部样式
.card-header {
  position: relative;
  height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  overflow: hidden;
  
  .card-cover {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-size: cover;
    background-position: center;
    filter: blur(20px) brightness(0.7);
    transform: scale(1.1);
    z-index: 1;
  }
  
  .card-avatar {
    position: relative;
    z-index: 2;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 4px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    
    &:hover {
      transform: scale(1.05);
      border-color: white;
    }
  }
  
  .card-info {
    position: relative;
    z-index: 2;
    text-align: center;
    margin-top: 12px;
    
    .card-name {
      color: white;
      font-size: 20px;
      font-weight: 600;
      margin: 0 0 8px 0;
      cursor: pointer;
      transition: all 0.3s ease;
      text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
      
      &:hover {
        transform: scale(1.02);
        text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
      }
    }
    
    .card-school {
      background: rgba(255, 255, 255, 0.9);
      color: #666;
      border: none;
      font-weight: 500;
    }
  }
}

// 卡片内容样式
.card-content {
  .member-tabs {
    :deep(.el-tabs__header) {
      margin: 0;
      background: #f8f9fa;
      
      .el-tabs__nav-wrap {
        &::after {
          display: none;
        }
      }
      
      .el-tabs__item {
        font-weight: 500;
        color: #666;
        transition: all 0.3s ease;
        
        &.is-active {
          color: #409eff;
          font-weight: 600;
        }
        
        &:hover {
          color: #409eff;
        }
      }
      
      .el-tabs__active-bar {
        background: linear-gradient(90deg, #409eff, #36cfc9);
        height: 3px;
      }
    }
    
    :deep(.el-tabs__content) {
      padding: 0;
    }
  }
  
  .tab-content {
    padding: 20px;
    min-height: 160px;
  }
}

// 内容区域样式
.content-section {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  
  .section-icon {
    color: #409eff;
    font-size: 18px;
    margin-top: 2px;
    flex-shrink: 0;
  }
  
  .section-content {
    flex: 1;
    
    .description {
      color: #666;
      line-height: 1.6;
      margin: 0;
      font-size: 14px;
      word-break: break-word;
    }
  }
}

// 工作信息样式
.work-info {
  .el-tag {
    padding: 8px 12px;
    font-size: 14px;
    
    .el-icon {
      margin-right: 6px;
    }
  }
}

// 联系方式列表样式
.contact-list {
  .contact-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
    
    &:last-child {
      border-bottom: none;
    }
    
    .contact-icon {
      color: #409eff;
      font-size: 16px;
      margin-top: 2px;
      flex-shrink: 0;
    }
    
    .contact-content {
      flex: 1;
      
      .contact-label {
        display: block;
        color: #999;
        font-size: 12px;
        margin-bottom: 4px;
        font-weight: 500;
      }
      
      .contact-value {
        color: #666;
        font-size: 14px;
        line-height: 1.4;
      }
      
      .contact-link {
        font-size: 14px;
        word-break: break-all;
        
        &:hover {
          text-decoration: underline;
        }
      }
    }
  }
}

// 响应式设计
@media (max-width: 768px) {
  .member-card {
    max-width: 100%;
    margin: 0;
  }
  
  .card-header {
    height: 160px;
    
    .card-info {
      .card-name {
        font-size: 18px;
      }
    }
  }
  
  .tab-content {
    padding: 16px;
    min-height: 140px;
  }
  
  .contact-list {
    .contact-item {
      padding: 10px 0;
      
      .contact-content {
        .contact-link {
          font-size: 13px;
        }
      }
    }
  }
}

@media (max-width: 480px) {
  .card-header {
    height: 140px;
    
    .card-avatar {
      :deep(.el-avatar) {
        width: 80px !important;
        height: 80px !important;
      }
    }
    
    .card-info {
      margin-top: 8px;
      
      .card-name {
        font-size: 16px;
      }
    }
  }
  
  .tab-content {
    padding: 12px;
    min-height: 120px;
  }
}
</style>
